-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-91133: tempfile.TemporaryDirectory: fix symlink bug in cleanup #99930
Conversation
During development, it becomes tiresome to have to manually clean up these files in case of unrelated TemporaryDirectory breakage.
✅ Deploy Preview for python-cpython-preview ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks to me like a good fix, thanks! A few comments.
Misc/NEWS.d/next/Library/2022-12-01-16-57-44.gh-issue-91133.LKMVCV.rst
Outdated
Show resolved
Hide resolved
This reverts commit d8f50e5.
Co-authored-by: Carl Meyer <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo one more comment. Thanks!
@serhiy-storchaka and @vstinner (as active committers into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I prefer to test with real filesystem. Mock tests are too fragile, they depend on implementation details that can be changed.
Lib/tempfile.py
Outdated
@@ -874,15 +874,22 @@ def __init__(self, suffix=None, prefix=None, dir=None, | |||
|
|||
@classmethod | |||
def _rmtree(cls, name, ignore_errors=False): | |||
def without_following_symlinks(func, path, *args): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to rename the function to "no_follow_symlinks" or "dont_follow_symlinks".
I dislike this trend to declare nested functions. Can't you move these functions at the module level, just make them private? This function doesn't use name nor ignore_errors.
GH-112838 is a backport of this pull request to the 3.12 branch. |
Sorry, @kwi-dk and @serhiy-storchaka, I could not cleanly backport this to
|
…up (pythonGH-99930) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
Sorry, @kwi-dk and @serhiy-storchaka, I could not cleanly backport this to
|
Sorry, @kwi-dk and @serhiy-storchaka, I could not cleanly backport this to
|
Sorry, @kwi-dk and @serhiy-storchaka, I could not cleanly backport this to
|
…n cleanup (pythonGH-99930) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
GH-112839 is a backport of this pull request to the 3.11 branch. |
I opened the issue this is fixing. Thank you all for the fix. |
GH-112840 is a backport of this pull request to the 3.10 branch. |
…n cleanup (pythonGH-99930) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
GH-112842 is a backport of this pull request to the 3.9 branch. |
… cleanup (pythonGH-99930) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
GH-112843 is a backport of this pull request to the 3.8 branch. |
… cleanup (pythonGH-99930) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
…nup (GH-99930) (GH-112838) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
…nup (GH-99930) (GH-112839) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]>
Thanks @kwi-dk for this fix. Thanks @serhiy-storchaka to taking the lead to update the code and merge the fix! |
…up (GH-99930) (GH-112843) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]>
…up (GH-99930) (GH-112842) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]>
…nup (GH-99930) (GH-112840) (cherry picked from commit 81c16cd) Co-authored-by: Søren Løvborg <[email protected]>
…up (pythonGH-99930) Co-authored-by: Serhiy Storchaka <[email protected]>
…up (pythonGH-99930) Co-authored-by: Serhiy Storchaka <[email protected]>
This PR fixes issue gh-91133, in which
TemporaryDirectory.cleanup
could try to fix permissions when deleting a symlink, but accidentally fix permissions of the target of the symlink instead.(It also changes thetest_flags
test case so it doesn't leave behindNOUNLINK
files when the test fails, which is just annoying when working on any change to theTemporaryDirectory
code.)Compatibility: There could conceivably be code out there relying on
TemporaryDirectory.cleanup
modifying permissions on files outside the tempdir being cleaned up, which the fixed code will no longer do.